package com.lwd.service.impl;

import com.lwd.entity.User;
import com.lwd.entity.UserExample;
import com.lwd.mapper.UserMapper;
import com.lwd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean register(User user) {

        int result = userMapper.insertSelective(user);

        return result > 0 ? true : false;
    }

    @Override
    public User login(User user) {
        UserExample example = new UserExample();
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andAccountEqualTo(user.getAccount()).andPasswordEqualTo(user.getPassword());
//        userExample.
        List<User> users = userMapper.selectByExample(example);
        if (users != null & users.size() != 0) {
            User u = users.get(0);

            return u;
        }

        return null;

    }

    @Override
    public List<User> getAllUserInfo() {
        List<User> users = userMapper.selectByExample(null);
        return users;
    }
}
